
function readLocalFile () {

   //得到了上传文件
   var filesArr = document.getElementsByName("File");
   //回显的地方
   var dataImgs = document.getElementsByName("ims");

   var localFile ;
   for ( var i= 0; i<filesArr.length; i++) {

    localFile = filesArr[i].files[0];
    var datasrc = dataImgs[i];
    (function(datasrc){

      var reader = new FileReader();
      reader.onload = function(event) {
        content = event.target.result;

        datasrc.src=content;
      }
      reader.onerror = function(event) {
       alert('获取图片数据失败')

     }
     content = reader.readAsDataURL(localFile,"UTF-8");

   })(datasrc);
 }
}


  function forUpload(){
    var filesArr = document.getElementsByName("File");

     var fileUUID = getUUID();
     var imgUUID = getUUID();

     for(var i=0;i<filesArr.length;i++){
      debugger;
      var localFile = filesArr[i].files[0];
      if(localFile==undefined){
        alert("请选择上传图片");
        return;
      }

      var reader = new FileReader();
      reader.onload = function(event) {
        content = event.target.result;

        var indexNum = content.lastIndexOf(",");
        var imageDate =  content.substring(indexNum+1);
        var fileData = new Object();
        fileData.ImageName=localFile.name;
        fileData.FileSize=localFile.size;
        fileData.ImageData=imageDate;
        fileData.FileUuid=fileUUID;
        fileData.ImageUuid=imgUUID;
        fileData.ImageFormat=localFile.type;
        var datas = JSON.stringify(fileData);
        var postUrl = API_URL+"image_info";
        $.ajax({
          url :postUrl,
          type: 'POST',
          data:datas,
          success : function(data) {
            alert("上传成功！");

          }
        });

      }
      reader.onerror = function(event) {
       alert('获取图片数据失败')

     }
     content = reader.readAsDataURL(localFile,"UTF-8");
   }
  
}

